package com.ibeifeng.jasperreport;

import java.util.HashMap;

import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class DemoJasperReport01_Jrxml {
	
	public static void main(String[] args) {
		//声明JasperReport对象
		JasperReport jasperReport = null;
		//声明JasperPrint对象
		JasperPrint jasperPrint = null;
		
		try {
			//编译".jrxml文件-->".jasper
			jasperReport=JasperCompileManager.compileReport("reports/report01.jrxml");
			
			//在报表生成前去填充报表内容
			jasperPrint = JasperFillManager.fillReport(jasperReport, //传入JasperReport实例
					new HashMap<String,Object>(),							//传入参数，若为空代表没有参数	
					new JREmptyDataSource());									//传入简单类代表空数据集
			
			//导出文件
			JasperExportManager.exportReportToPdfFile(jasperPrint,"jasperreport01.pdf");
		} catch (JRException e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}
